#!/usr/bin/env python
#coding:utf-8

import wx
import wx.aui
import constants as CS
import utils

from layout import *
from widgets import *
	

class MainFrame(wx.Frame):

	def __init__(self):
		wx.Frame.__init__(self,None,-1,CS.TXT_TITLE_MAIN_FRAME,(0,0),CS.PAIR_SIZE_MAIN_FRAME)
		
		self._mgr = wx.aui.AuiManager(self)
		self.SetMenuBar( self.__createMenuBar__() )
		
		self.modes = [EletrostaticaLayoutModel(self)]

		self.selectedMode = 0
		self.loadMode()

		
	def __createMenuBar__(self):
		menuBar = wx.MenuBar()
		
		#Menu File
		menu_file = wx.Menu()
		
		menu_file.Append( wx.NewId(), "&" + CS.TXT_MENU_NEW, CS.TXT_MENU_NEW_TIP )	
		menu_file.AppendSeparator()
		
		menu_file.Append( wx.NewId(), "&" + CS.TXT_MENU_OPEN, CS.TXT_MENU_OPEN_TIP )	
		menu_file.Append( wx.NewId(), "&" + CS.TXT_MENU_SAVE, CS.TXT_MENU_SAVE_TIP )
		menu_file.Append( wx.NewId(), "&" + CS.TXT_MENU_SAVEAS, CS.TXT_MENU_SAVEAS_TIP )				
		menu_file.AppendSeparator()
		
		menu_exit_item = menu_file.Append( wx.NewId(), "&" + CS.TXT_MENU_EXIT, CS.TXT_MENU_EXIT_TIP )			
		self.Bind( wx.EVT_MENU, self.closeFrame, menu_exit_item)
		
		#Menu Mode
		menu_mode = wx.Menu()
		
		menu_mode.Append( wx.NewId(), "&" + CS.TXT_MENU_MECHANICS, CS.TXT_MENU_MECHANICS_TIP)
		menu_mode.Append( wx.NewId(), "&" + CS.TXT_MENU_ELETROSTATIC, CS.TXT_MENU_ELETROSTATIC_TIP)
		
		#Menu Simulation
		menu_sim = wx.Menu()
		
		menu_sim.Append( wx.NewId(), "&" + CS.TXT_MENU_RUN, CS.TXT_MENU_RUN_TIP)
		menu_sim.Append( wx.NewId(), "&" + CS.TXT_MENU_PAUSE, CS.TXT_MENU_PAUSE_TIP)		
		menu_sim.Append( wx.NewId(), "&" + CS.TXT_MENU_STOP, CS.TXT_MENU_STOP_TIP)		
		menu_sim.AppendSeparator()
		
		scripts = utils.General.listScripts()
		submenu_script = wx.Menu()
		
		#SubMenu Sripts
		for s in scripts:
			submenu_script.Append( wx.NewId(), "&" + s )
		
		menu_sim.AppendSubMenu(submenu_script,"&" + CS.TXT_MENU_SCRIPT,CS.TXT_MENU_SCRIPT_TIP)

		
		#Adding to MenuBar
		menuBar.Append(menu_file,"&" + CS.TXT_MENU_FILE)
		menuBar.Append(menu_mode,"&" + CS.TXT_MENU_MODE)
		menuBar.Append(menu_sim,"&" + CS.TXT_MENU_SIMULATION)
		
		return menuBar
		
	def loadMode(self):
		mode = self.modes[self.selectedMode]
		
		viewbox = mode.getViewBox()
		toolbox = mode.getToolBox()
		infobox = mode.getInfoBox()
		
		self._mgr.AddPane(viewbox,wx.CENTER,"View")
		self._mgr.AddPane(toolbox,wx.RIGHT,"Toolbox")
		self._mgr.AddPane(infobox,wx.BOTTOM,"Infobox")
		
		self._mgr.Update()
		
	def closeFrame(self,event):
		self.Destroy()		
		

class App(wx.App):
    
	def OnInit(self):
		frame = MainFrame()
		frame.Show()
		return True
	

if __name__ == '__main__':
	app = App(False)
	app.MainLoop()	
	
